package com.mdlib.helper.api.service;

import com.mdlib.helper.model.BaseResult;
import com.mdlib.helper.model.entity.AccountInfo;
import com.mdlib.helper.model.entity.AgreementEntity;
import com.mdlib.helper.model.entity.AppAfterInfo;
import com.mdlib.helper.model.entity.AppFrontInfo;

import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by librabin on 16/11/7.
 */

public interface AccountApi {

    /**
     * 本地登录
     *
     * @param phone
     * @param password
     * @param clientType
     * @return
     */
    @FormUrlEncoded
    @POST("user/login")
    Observable<BaseResult<AccountInfo>> doLogin(@Field("phone") String phone,
                                                @Field("password") String password,
                                                @Field("origin") String clientType,
                                                @Field("device_token") String deviceToken,
                                                @Field("login_type") String type
    );

    /**
     * 短信登录
     *
     * @param phoneNum
     * @param phoneCode
     * @param clientType
     * @param loginType
     * @return
     */
    @FormUrlEncoded
    @POST("user/message_login")
    Observable<BaseResult<AccountInfo>> doMsgLogin(@Field("phone") String phoneNum,
                                                   @Field("code") String phoneCode,
                                                   @Field("origin") String clientType,
                                                   @Field("device_token") String deviceToken,
                                                   @Field("login_type") String loginType
    );

    /**
     * 微信登陆
     *
     * @param uid
     * @param nickName
     * @param avatarUrl
     * @param sex
     * @param clientType
     * @return
     */
    @FormUrlEncoded
    @POST("user/wx_login")
    Observable<BaseResult<AccountInfo>> doAuthLogin(@Field("unionid") String uid,
                                                    @Field("nick_name") String nickName,
                                                    @Field("img_url") String avatarUrl,
                                                    @Field("sex") String sex,
                                                    @Field("device_token") String deviceToken,
                                                    @Field("origin") String clientType
    );


    /**
     * 注册接口
     *
     * @param phoneNum
     * @param password
     * @param phoneCode
     * @param origin
     * @return
     */
    @FormUrlEncoded
    @POST("user/register")
    Observable<BaseResult> register(@Field("phone") String phoneNum,
                                    @Field("password") String password,
                                    @Field("phone_code") String phoneCode,
                                    @Field("origin") String origin
    );


    /**
     * 获取手机号验证码
     *
     * @param phoneNum
     * @param codeType
     * @return
     */
    @FormUrlEncoded
    @POST("user/get_phone_code")
    Observable<BaseResult> featchPhoneCode(@Field("phone") String phoneNum,
                                           @Field("type") String codeType
    );


    /**
     * @param phoneNum
     * @param phoneCode
     * @param codeType
     * @return
     */
    @FormUrlEncoded
    @POST("user/verify_phone_code")
    Observable<BaseResult> verifyPhoneCode(@Field("phone") String phoneNum,
                                           @Field("code") String phoneCode,
                                           @Field("type") String codeType
    );


    /**
     * 忘记密码
     *
     * @param newPwd
     * @param phoneNum
     * @return
     */
    @FormUrlEncoded
    @POST("user/forgot_password")
    Observable<BaseResult> setNewPwd(@Field("password") String newPwd,
                                     @Field("phone") String phoneNum

    );


    /**
     * 登录前获取初始化参数
     *
     * @return
     */
    @POST("system/init_before_login")
    Observable<BaseResult<AppFrontInfo>> featchAppFrontInfo();


    /**
     * 获取初始化参数
     *
     * @return
     */
    @POST("system/init")
    Observable<BaseResult<AppAfterInfo>> getAppAfterInfo();


    /**
     * 获取用户协议
     *
     * @return
     */
    @POST("article/get_reg_agreement")
    Observable<BaseResult<AgreementEntity>> featchRegAgreement();

    /**
     * 获取跑客注册协议
     *
     * @return
     */
    @POST("article/get_run_reg_agreement")
    Observable<BaseResult<AgreementEntity>> featchRunAgreement();

    @FormUrlEncoded
    @POST("user/bind_phone")
    Observable<BaseResult> bindPhone(@Field("unionid") String unionid,
                                     @Field("phone") String phone,
                                     @Field("password") String password,
                                     @Field("code") String code);
}
